//
//  LauEmotionModel.swift
//  表情包数据
//
//  Created by Lausen on 2017/5/16.
//  Copyright © 2017年 id. All rights reserved.
//

import UIKit
import YYModel

class LauEmotionModel: NSObject {

    /// 这个是表情的类型 0就是图片 / 1就是emoji
    var type = false
    /// 这个是图片的描述,用来传递到服务器上去的,节省用户的流量
    var chs: String?
    /// 这个是图片的名称
    var png: String?
    /// emoji的十六进制码
    var code: String?
    /// 路径
    var directory: String?
    
    var image: UIImage?{
        
        if type == true{
            
            return nil
        }
        
        guard let path = Bundle.main.path(forResource: "Emoticons.bundle", ofType: nil),
            let bundle = Bundle.init(path: path),
            let directory = directory,
            let png = png
        else{
                
                return nil
        }
        
        return UIImage(named: "\(directory)/\(png)", in: bundle, compatibleWith: nil)
    }
    
    
    override var description: String{
        
        return yy_modelDescription()
    }
    
    func imageText(font: UIFont) -> NSAttributedString {
        
        guard let image = image else {
            
            return NSAttributedString(string: "错误的")
        }
        
        //1:创建图片附件
        let attachment = NSTextAttachment()
        attachment.image = image
        
        let height = font.lineHeight
        
        //2:设置附件的bounds
        attachment.bounds = CGRect(x: 0, y: -4, width: height, height: height)
        
        return NSAttributedString(attachment: attachment)
    }
}
